<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<DecisionMaking.BusinessLogic.Model.AlgorithmDefinitionModel>" MasterPageFile="~/Views/Shared/Site.Master" %>

<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
    <script src="<%= Url.Content("~/Scripts/codemirror/codemirror.js")%>" type="text/javascript"></script>    
    <script src="<%= Url.Content("~/Scripts/codemirror/mirrorframe.js")%>" type="text/javascript"></script>    
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"><%=Model.DefinitionId == null ? "New" : "Edit"%> Algorithm</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.ValidationSummary("Algorithm creation was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm("Save", "Algorithms"))
       {%>
        <fieldset>
            <legend>Algorithm Details</legend>
        	<%=Html.HiddenFor(m => m.DefinitionId)%>
        	<%=Html.HiddenFor(m => m.AccountId)%>
            <p class="field-multi-line field-textbox">
                <%=Html.LabelFor(m => m.Name)%>
                <%=Html.TextBoxFor(m => m.Name)%>
                <%=Html.ValidationMessageFor(m => m.Name)%>
            </p>
            <p class="field-multi-line field-combo">
                <%=Html.LabelFor(m => m.Engine)%>
                <%=Html.DropDownListFor(m => m.Engine,
                                                  new SelectList((IDictionary<string, string>) ViewData["engines"],
                                                                 "Value", "Key"))%>
                <%=Html.ValidationMessageFor(m => m.Engine)%>
            </p>                
        </fieldset>
        <fieldset>
            <legend>Code</legend>
            <div class="code-editor-wrappper">
                <%=Html.TextAreaFor(m => m.Code, new Dictionary<string, object>(){{"rows", 30}, {"cols", 100}})%>
            </div>
            <%=Html.ValidationMessageFor(m => m.Code)%>
            <script type="text/javascript">
                var editor = CodeMirror.fromTextArea('Code', {
                    height: "600px",
                    parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
                    stylesheet: '<%= Url.Content("~/Content/codemirror/jscolors.css")%>',
                    path: '<%= Url.Content("~/Scripts/codemirror/")%>',
                    autoMatchParens: true,
                    lineNumbers: true
                });
            </script>
        </fieldset>
        <p>
            <input type="submit" value="<%=Model == null ? "Create" : "Save"%> " />
        </p>               
    <% } %>
</asp:Content>